home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / (Samples) / Test Programs / TestPrinter / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-21  |  2.9 KB  |  173 lines

  1. /*    main.cpp
  2.  *
  3.  *        This is the actual core which makes this thing fly.
  4.  */
  5.  
  6. #include <string.h>
  7. #include <XApplication.h>
  8. #include <XWindow.h>
  9. #include <XDialog.h>
  10. #include <XPrinter.h>
  11.  
  12. /************************************************************************/
  13. /*                                                                        */
  14. /*    Printer Test                                                        */
  15. /*                                                                        */
  16. /************************************************************************/
  17.  
  18. /*    DoPageSetup
  19.  *
  20.  *        Page setup
  21.  */
  22.  
  23. static void DoPageSetup(void)
  24. {
  25.     GPrinter.PageSetup();
  26. }
  27.  
  28. /*    PrintPage
  29.  *
  30.  *        Print a test page
  31.  */
  32.  
  33. static void PrintPage(XGPrinter *p)
  34. {
  35.     Rect r;
  36.     XGDraw draw(p);
  37.     
  38.     r = p->PrintSize();
  39.  
  40. #if OPT_MACOS == 1
  41.     ::MoveTo(r.left+5,r.top+30);
  42.     ::DrawString("\pThis is a simple page printout test");
  43. #endif
  44.  
  45. #if OPT_WINOS == 1
  46.     ::DrawText(draw.GetDC(),"This is a simple page printout test",
  47.             -1,&r,DT_SINGLELINE | DT_TOP | DT_NOPREFIX);
  48. #endif
  49. }
  50.  
  51. /*    DoPrintTest
  52.  *
  53.  *        Print test
  54.  */
  55.  
  56. static void DoPrintTest(void)
  57. {
  58.     short s,e;
  59.     
  60.     if (GPrinter.PrintJob(&s,&e)) {
  61.         /*
  62.          *    Print a test page
  63.          */
  64.         
  65.         if (GPrinter.StartJob("NewGUI6 Print Test")) {
  66.             if (GPrinter.StartPage()) {
  67.                 PrintPage(&GPrinter);
  68.                 GPrinter.EndPage();
  69.             }
  70.             GPrinter.EndJob();
  71.         }
  72.     }
  73. }
  74.  
  75. /************************************************************************/
  76. /*                                                                        */
  77. /*    My app                                                                */
  78. /*                                                                        */
  79. /************************************************************************/
  80.  
  81. /*    TMyApp
  82.  *
  83.  *        My application
  84.  */
  85.  
  86. class TMyApp : public XGAppSingleWindow {
  87.     public:
  88.         long    ReceiveDispatch(long msg, long arg, void *parg);
  89. };
  90.  
  91. /*    TMyApp::ReceiveDispatch
  92.  *
  93.  *        Do my test
  94.  */
  95.  
  96. long TMyApp::ReceiveDispatch(long msg, long arg, void *parg)
  97. {
  98.     if (!IsModalWindow()) {
  99.         if (msg == KEventDoMenuCommand) {
  100.             if (arg == 102) {
  101.                 DoPageSetup();
  102.                 return 1;
  103.             }
  104.             if (arg == 103) {
  105.                 DoPrintTest();
  106.                 return 1;
  107.             }
  108.         } else if (msg == KEventGetMenuStatus) {
  109.             if ((arg >= 100) || (arg <= 103)) {
  110.                 ((XGSMenuStatusRecord *)parg)->enable = true;
  111.                 return 1;
  112.             }
  113.         }
  114.     }
  115.         
  116.     return XGAppSingleWindow::ReceiveDispatch(msg,arg,parg);
  117. }
  118.  
  119. /************************************************************************/
  120. /*                                                                        */
  121. /*    Main entry point                                                    */
  122. /*                                                                        */
  123. /************************************************************************/
  124.  
  125. /*    StartApplication
  126.  *
  127.  *        This starts up the application
  128.  */
  129.  
  130. XGAppCore *StartApplication(void)
  131. {
  132.     XGAppSingleWindow *aw;
  133.     XGWindow *w;
  134.     XGSWindowInitRecord wi;
  135.     
  136.     /*
  137.      *    Start application engine
  138.      */
  139.     
  140.     aw = new TMyApp;
  141.     
  142.     /*
  143.      *    Start window
  144.      */
  145.     
  146.     wi.fViewType = 'wind';
  147.     wi.windowType = KWinTypeDocument;
  148.     wi.windowID = 0;
  149.     wi.fVisible = true;
  150.     wi.screenLeft = 0;
  151.     wi.screenTop = 0;
  152.     wi.screenRight = 205;
  153.     wi.screenBottom = 331;
  154.     
  155.     wi.minx = -1;
  156.     wi.miny = -1;
  157.     wi.maxx = -1;
  158.     wi.maxy = -1;
  159.     wi.initx = -1;
  160.     wi.inity = -1;
  161.     wi.zoomx = -1;
  162.     wi.zoomy = -1;
  163.     
  164.     strcpy(wi.windowName,"Test window");
  165.     w = new XGWindow(wi);
  166.     
  167.     /*
  168.      *    Done. Return
  169.      */
  170.     
  171.     return aw;
  172. }
  173.